package com.smarthospital.web.controller;

import com.smarthospital.common.Result.CodeMsg;
import com.smarthospital.common.Result.CommonException;
import com.smarthospital.common.Result.ResultDTO;
import com.smarthospital.contants.SHConst;
import com.smarthospital.entity.pojo.SHDictionary;
import com.smarthospital.entity.pojo.User;
import com.smarthospital.service.CommonService;
import com.smarthospital.service.FileService;
import com.smarthospital.service.RTCService;
import com.smarthospital.web.inteceptor.LoginInterceptor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * create by sym  2020/8/16 16:00.
 */
@RestController
@Slf4j
@RequestMapping("/rtc")
@Api(description = "音视频通讯 通知接口",value = "rtc")
public class RTCController {

    @Autowired
    private RTCService rtcService;

    @Autowired
    private StringRedisTemplate redisTemplate;

    @GetMapping("/videoAdvice")
    @ApiOperation(value = "音视频通知",
                    notes = "param: type -> 类型 0_视频 1_音频\n"+
                             "      orderId -> 订单号 \n"+
                             "      piont -> 0_开始 1_结束")
    public ResultDTO videoAdvice(@RequestParam("type") Integer type,@RequestHeader("SH_TOKEN")String SH_TOKEN,
                            @RequestParam("orderId") String  orderId,@RequestParam("piont") Integer piont){
        log.info("videoAdvice type {} orderId {} piont {}",type,orderId,piont);
        int leftTime = rtcService.videoAdvice(orderId, type, piont);
        return ResultDTO.sucess(leftTime);
    }

    @GetMapping("/check")
    @ApiOperation(value = "音视频校验 code返回0 即可发起通话",
            notes = "param:     orderId -> 订单号 \n")
    public ResultDTO check(@RequestHeader("SH_TOKEN")String SH_TOKEN, @RequestParam("orderId") String  orderId){
        log.info("check orderId {} piont {}",orderId);
        rtcService.check(orderId);
        return ResultDTO.sucess();
    }



}
